#!/bin/bash

# [ is a synonym for test (but requires a final argument of ])

# numeric
val1=10
val2=11
if [ $val1 -gt 5 ]; then
    echo "The test value $val1 is greater than 5"
fi
if [ $val1 -eq $val2 ]; then
    echo "The values are equal"
else
    echo "The values are different"
fi

# string (escape needed)
val1=baseball
val2=hockey
if [ $val1 \> $val2 ]; then
    echo "$val1 is greater than $val2"
else
    echo "$val1 is less than $val2"
fi

# file operation
if [ -e $HOME ]; then
    echo "The object exists, is it a file?"
    if [ -f $HOME ]; then
        echo "Yes, it is a file!"
    else
        echo "No, it is not a file!"
        if [ -f $HOME/.bash_history ]; then
            echo "But this is a file!"
        fi
   fi
else
    echo "Sorry, the object does not exist."
fi

# compound
if [ -d $HOME ] && [ -w $HOME/testing ]; then
    echo "The file exists and you can write to it"
else
    echo "I cannot write to the file"
fi

# double parentheses: advanced mathematical formulas for comparisons, no escape.
val1=10
if (( $val1 ** 2 > 90 )); then
    (( val2 = $val1 ** 2 ))
    echo "The square of $val1 is $val2"
fi

# double brackets: provides advanced features for string comparisons, no escape.
if [[ $USER == r* ]]; then
    echo "Hello $USER"
else
    echo "Sorry, I do not know you"
fi

